
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
Vue.config.productionTip = false
import { initGlobalState,registerMicroApps, start  } from 'qiankun'
 
  const initialState = {
    // 当前登录用户
    userInfo: "55555"
  }
    const microApps = [
    {
      name: "sub01",
      entry: 'http://localhost:9957',
      activeRule: "/sub01",
      container:"#vue",
       props: {
            globalState: initialState
          }
    },
    {
      name: "sub02",
      entry: 'http://localhost:9958',
      activeRule: "/sub02",
      container:"#vue",
       props: {
            globalState: initialState
          }
    },
  ];
  registerMicroApps(microApps)
  start({
    sandbox: { strictStyleIsolation: true }, // 可选，是否开启沙箱，默认为 true。// 从而确保微应用的样式不会对全局造成影响。
    singular: true // 可选，是否为单实例场景，单实例指的是同一时间只会渲染一个微应用。默认为 true。
  })
  const qiankunActions = initGlobalState(initialState)
  qiankunActions.onGlobalStateChange((state) => {
    for (const key in state) {
      if (key === 'userInfo') {
        console.log("state",state[key])
      }
    }
  })
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
